
#include "Log.h"
#include <fstream>

namespace FlameEngine
{
	using namespace std;

	std::ofstream Log::m_fstream("log.txt");
	LogMsgLevel Log::m_logLevel = lml_all;
	uint32_t Log::m_msgFilter = 0xffffffff;

	void Log::WriteLine(char* msg,LogMsgLevel msgLvl,uint32_t channel)
	{
		if(msgLvl <= m_logLevel)
		{
			if((channel & m_msgFilter) == channel)
			{
				if(!m_fstream.fail())
				{
					m_fstream<<msg<<"\n";
					m_fstream.flush();
				}
#ifdef _DEBUG
				//write to VS ouput window
				OutputDebugStringA(msg);
				OutputDebugStringA("\n");
#endif
				
			}
		}
	}

	void Log::SetMsgFilter(uint32_t filterMask)
	{
		m_msgFilter = filterMask;
	}

	uint32_t Log::GetMsgFilter()
	{
		return m_msgFilter;
	}

	void Log::SetOutputLevel(LogMsgLevel level)
	{
		m_logLevel = level;
	}

	void Log::EnableChannel(uint32_t channel,bool enable)
	{
		if(enable)
		{
			m_msgFilter |= channel;
		}
		else
		{
			m_msgFilter &= (!channel);
		}
	}
}